//路由鉴权:就是路由能不能被访问到权限设置->全局守卫完成
import router from "./router";
import Nprogress from 'nprogress'
import useUserStore from '@/store/modules/user';

import pinia from '@/store'
const useUser = useUserStore(pinia);
import "nprogress/nprogress.css"
Nprogress.configure({ showSpinner: false });
//存储用户未登录可以访问路由得路径
const whiteList = ["/home", '/hospital/register', '/hospital/detail', '/hospital/notice', '/hospital/close', '/hospital/search'];

//前置守卫
router.beforeEach((to, from, next) => {
  //访问路由组件的之前,进度条开始动
  Nprogress.start();
  //动态设置网页左上角的标题
  document.title = `尚医通-${to.meta.title}`;
  next()

  // if(useUser.userInfo.token || whiteList.includes(to.path)){
  //   next()
  // }else{
  //   useUser.visiable = true
  //   next({path:'/home', query:{redirect:to.fullPath}})
  // }
});

//后置路由
router.afterEach((to, from) => {
  //访问路由组件成功,进度条消息
  Nprogress.done();
})